package net.cyue.easyconfiguration.node.definition;

import net.cyue.easyconfiguration.node.NodeType;
import net.cyue.easyconfiguration.node.api.INodeTypeConverter;

import java.util.HashMap;
import java.util.Map;

public class TableNodeDefinition extends AbstractNodeDefinition {

    private Map<String, AbstractNodeDefinition> fieldDefinitionMap = new HashMap<>();

    public TableNodeDefinition(
        AbstractNodeDefinition parent,
        String name,
        String... paths
    ) {
        super(parent, NodeType.TABLE, name, paths);
    }
    public TableNodeDefinition(
        AbstractNodeDefinition parent,
        INodeTypeConverter<Map<String, Object>, ?> typeConverter,
        String name,
        String... paths
    ) {
        super(parent, NodeType.TABLE, typeConverter, name, paths);
    }

    public void addFieldDefinition(String fieldName, AbstractNodeDefinition fieldDefinition) {
        fieldDefinitionMap.put(fieldName, fieldDefinition);
    }

    public void setFieldDefinitionMap(Map<String, AbstractNodeDefinition> fieldDefinitionMap) {
        this.fieldDefinitionMap = fieldDefinitionMap;
    }

    public Map<String, AbstractNodeDefinition> getFieldDefinitionMap() {
        return fieldDefinitionMap;
    }
    public AbstractNodeDefinition getFieldDefinition(String fieldName) {
        return fieldDefinitionMap.get(fieldName);
    }
    public AbstractNodeDefinition[] getFieldDefinitions() {
        return this.fieldDefinitionMap.values().toArray(new AbstractNodeDefinition[0]);
    }
}
